var basePage = require('../../common/BasePage');
Page({
    behaviors: [basePage],
    data: {
        page: 1,
        totalPages: 0,
        loading: false
    },
    onShow: function() {
        this.getCoupon()
    },
    getCoupon() {
        this.setData({ loading: true })
        let that = this
        this.request({
            url: this.data.host + '/home/user/coupon',
            data: {
                page: this.data.page
            }
        }, function(data) {
            let couponList = that.data.couponList || []
            couponList = [...couponList, ...data.data]
            that.setData({ couponList: couponList, totalPages: data.pages, loading: false })
        })
    },
    login_reload() {
        this.getCoupon()
    },
    onReachBottom: function() {
        if (this.data.page >= this.data.totalPages) return
        let { page } = this.data
        page++
        this.setData({ page })
        this.getCoupon()
    },
    onHide: function() {
        this.setData({ couponList: null })
    },
})